/**
 * Project		:	TAO Library
 * Created		:	25.09.2013
 * Author		:	Alexandr Tsvetkov
 */
package ua.at.tsvetkov.ui;

import ua.at.tsvetkov.application.AppConfig;
import android.util.DisplayMetrics;

/**
 * @author Alexandr Tsvetkov
 */
public class AppScreen {

	private static final int	ORIGINAL_VIEW_WIDTH		= 768;
	private static final int	ORIGINAL_VIEW_HEIGHT		= 1184;
	private static final int	ORIGINAL_VIEW_DIAGONAL	= calcDiagonal(ORIGINAL_VIEW_WIDTH, ORIGINAL_VIEW_HEIGHT);

	private static int			mWidth;
	private static int			mHeight;
	private static int			mDiagonal;
	private static float			mDensity;

	static {
		DisplayMetrics metrics = AppConfig.getContext().getResources().getDisplayMetrics();
		mWidth = metrics.widthPixels;
		mHeight = metrics.heightPixels;
		mDiagonal = calcDiagonal(mWidth, mHeight);
		mDensity = metrics.density;
	}

	public static int getWidth() {
		return mWidth;
	}

	public static int getHeight() {
		return mHeight;
	}

	public static int widthScale(int value) {
		return (int) Math.round(value * mWidth / (float) ORIGINAL_VIEW_WIDTH);
	}

	public static int heightScale(int value) {
		return (int) Math.round(value * mHeight / (float) ORIGINAL_VIEW_HEIGHT);
	}

	public static int diagonalScale(int value) {
		return (int) Math.round(value * mDiagonal / (float) ORIGINAL_VIEW_DIAGONAL);
	}

	public static int pxFromDp(int dp) {
		return (int) Math.round(dp * mDensity);
	}

	private static int calcDiagonal(int width, int height) {
		return (int) Math.round(Math.sqrt(width * width + height * height));
	}
	
}
